package edu.cuit.campus.service.bean;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.cuit.campus.mapper.CompanyMapper;
import edu.cuit.campus.po.Company;
import edu.cuit.campus.service.CompanyService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/8/15 11:23
 */
@Service
@Transactional
public class CompanyServiceBean implements CompanyService {
    @Resource private CompanyMapper mapper;
    @Override
    public Integer save(Company company) {
        mapper.insert(company);
        return company.getId();
    }

    @Override
    public void removeById(Integer id) {
        mapper.removeById(id);
    }

    @Override
    public void updateById(Company company) {
        mapper.updateById(company);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public Company findById(Integer id) {
        return mapper.findById(id);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public PageInfo<Company> list(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<Company> companies = mapper.limit();
        return new PageInfo<>(companies);
    }
}
